package org.easymis.crm.modules.oa.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.easymis.commons.web.BaseController;
import org.easymis.commons.web.utils.Page;
import org.easymis.commons.web.utils.R;
import org.easymis.crm.modules.oa.entitys.mybatis.dto.OaDiary;
import org.easymis.crm.modules.oa.service.OaDiaryService;
import org.easymis.crm.modules.system.entitys.mybatis.dto.Member;
import org.easymis.crm.modules.system.service.OrganizeFunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags = "日报管理|工作日志")
@Controller
public class OaDiaryDayAction extends BaseController{
	@Resource
	private OaDiaryService service;
	@Autowired
	OrganizeFunctionService organizeFunctionService;
	@ApiOperation(value = "日报管理首页", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@RequestMapping(value = { "/oa/diary/day/index.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String index(@ModelAttribute Page page, ModelMap map) throws Exception {
		return getTplPath(map, "oa/diary/day/index");
	}

	@ApiOperation(value = "日报分页列表", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@RequestMapping(value = { "/oa/diary/day/list.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String list(@ModelAttribute Page page, ModelMap map) throws Exception {
		return getTplPath(map, "oa/diary/day/list");
	}

	@ApiOperation(value = "日报分页列表", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/oa/diary/day/list.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R listJson(@ModelAttribute Page page, ModelMap map) throws Exception {
		PageHelper.startPage(page.getCurPage(), page.getPageSize());
		List diaryList = service.getList(new OaDiary());
		PageInfo<OaDiary> p = new PageInfo<OaDiary>(diaryList);
		return new R().put("pageInfo", p);
	}

	@ApiOperation(value = "添加日报", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@RequestMapping(value = { "/oa/diary/day/add.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String forwardAdd(@ModelAttribute Page page, ModelMap map) throws Exception {

		return getTplPath(map, "add");
	}

	@ApiOperation(value = "添加日报", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/oa/diary/day/save.do" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R save(@ModelAttribute Page page, ModelMap map,HttpSession session,OaDiary bean) throws Exception {
		Member userInfo =(Member)session.getAttribute("userInfo");

/*		bean.setOrgId(userInfo.getOrgId());
		bean.setStaffId(userInfo.getStaffId());
		bean.setType(1);
		bean.setStatus(1);
		bean.setReviewWorkLevel(0);*/
		return new R().ok();
	}

	@ApiOperation(value = "删除日报", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/oa/diary/day/delete.do" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R delete(@ModelAttribute Page page, ModelMap map) throws Exception {
		return new R().ok();
	}

	@ApiOperation(value = "编辑日报", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@RequestMapping(value = { "/oa/diary/day/edit.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String forwardEdit(@ModelAttribute Page page, ModelMap map) throws Exception {
		return getTplPath(map, "edit");
	}

	@ApiOperation(value = "修改日报", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/oa/diary/day/update.do" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R update(@ModelAttribute Page page, ModelMap map) throws Exception {
		return new R().ok();
	}

	@ApiOperation(value = "日报详情", notes = "JSON ", produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@RequestMapping(value = { "/oa/diary/day/view.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R viewJson(@ModelAttribute Page page, ModelMap map) throws Exception {
		return new R().ok();
	}

	@ApiOperation(value = "日报详情", notes = "html", produces = MediaType.APPLICATION_JSON_VALUE)
	@RequestMapping(value = { "/oa/diary/day/view.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String view(@ModelAttribute Page page, ModelMap map) throws Exception {
		return getTplPath(map, "/oa/diary/day/view");
	}

}
